package com.tencent.wxcloudrun.config;
import com.github.xiaoymin.knife4j.spring.extension.OpenApiExtensionResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @author lichongbing
 * @version V1.0
 * @desc swagger3配置类
 * @copyright &copy; DYH
 * @date 2021-09-13-21:00
 * @address 成都
 */
@EnableOpenApi
@Configuration
@Import(BeanValidatorPluginsConfiguration.class)
public class Swagger3Config {

    private final OpenApiExtensionResolver openApiExtensionResolver;

    @Autowired
    public Swagger3Config(OpenApiExtensionResolver openApiExtensionResolver) {
        this.openApiExtensionResolver = openApiExtensionResolver;
    }

    @Bean
    public Docket taxationDocket() {
        return new Docket(DocumentationType.OAS_30)
                .groupName("扫码点餐前台接口API")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.tencent.wxcloudrun.frontcontroller"))
                .paths(PathSelectors.any())
                .build()
                .extensions(openApiExtensionResolver.buildExtensions("扫码点餐前端接口API"));
    }

    @Bean
    public Docket taxationDockets() {
        return new Docket(DocumentationType.OAS_30)
                .groupName("扫码点餐后台接口API")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.tencent.wxcloudrun.backcontroller"))
                .paths(PathSelectors.any())
                .build()
                .extensions(openApiExtensionResolver.buildExtensions("扫码点餐后台接口API"));
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("扫码点餐API文档")
                .description("扫码点餐")
                .version("1.0.0")
                .contact(new Contact("lichongbing", "http://192.168.1.109:8000/doc.html", "873610008@qq.com"))
                .termsOfServiceUrl("http://192.168.1.109:8000")
                .build();
    }
}
